<style scoped lang="scss">
	.noin {
		margin-top: 200upx;
	}

	.nolog {
		text-align: center;
		font-size: 32upx;
		padding: 40upx 20upx;
	}
</style>
<template>
	<view class="">
		<web-view v-if="hasLogin" :src="url"></web-view>
		<view v-else class="noin">
			<view class="nolog">
				亲，小程序访问商城请先登录哦!
			</view>
			<view class="nolog">
				请先登录柔性星球!
			</view>
		</view>
		<!-- 未登录登陆组件 -->
		<login ref="login"></login>
	</view>
</template>

<script>
	import {
		$storage
	} from "@/utils";
	export default {
		data() {
			return {
				url: "",
				hasLogin: false
			};
		},
		async onShow(){
			await this.$u.api.checkLogin();
		},
		async onLoad(options) {
			this.hasLogin = await this.$u.api.checkLogin();
			if (this.hasLogin) {
				this.url = this.estoreBaseUrl + "/mobile/user/tokenLogin.html?token=" +
					$storage.get("passportToken") +
					"&redirect_url=" + encodeURI(options.url) +
					"&wxminapp=1" + 
					"&device_id=" + $storage.get("rouyu-device-id");
			}
			// 登陆成功后个跳转到对应的页面
			uni.$on('after:login', () => {
				this.url = this.estoreBaseUrl + "/mobile/user/tokenLogin.html?token=" +
					$storage.get("passportToken") +
					"&redirect_url=" + encodeURI(options.url) +
					"&wxminapp=1" +
					"&device_id=" + $storage.get("rouyu-device-id");
			})

		},
	};
</script>
